package com.inno.life.infra.basic.service.impl;

import com.inno.life.infra.basic.entity.PlannerMessages;
import com.inno.life.infra.basic.mapper.PlannerMessagesDao;
import com.inno.life.infra.basic.service.PlannerMessagesService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * (PlannerMessages)表服务实现类
 *
 * @author makejava
 * @since 2024-12-07 23:06:50
 */
@Service("plannerMessagesService")
public class PlannerMessagesServiceImpl implements PlannerMessagesService {
    @Resource
    private PlannerMessagesDao plannerMessagesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PlannerMessages queryById(Long id) {
        return this.plannerMessagesDao.queryById(id);
    }



    /**
     * 新增数据
     *
     * @param plannerMessages 实例对象
     * @return 实例对象
     */
    @Override
    public PlannerMessages insert(PlannerMessages plannerMessages) {
        this.plannerMessagesDao.insert(plannerMessages);
        return plannerMessages;
    }

    /**
     * 修改数据
     *
     * @param plannerMessages 实例对象
     * @return 实例对象
     */
    @Override
    public PlannerMessages update(PlannerMessages plannerMessages) {
        this.plannerMessagesDao.update(plannerMessages);
        return this.queryById(plannerMessages.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.plannerMessagesDao.deleteById(id) > 0;
    }

    @Override
    public List<PlannerMessages> queryList(PlannerMessages plannerMessages) {
        return this.plannerMessagesDao.queryList(plannerMessages);
    }

    @Override
    public void readAllByUserId(Long userId) {
        this.plannerMessagesDao.readAllByUserId(userId);
    }

    @Override
    public Integer unreadCount(PlannerMessages plannerMessages) {
       return Math.toIntExact(this.plannerMessagesDao.count(plannerMessages));
    }
}
